package com.ruoyi.report.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.report.model.DataEntity;
import com.ruoyi.report.model.RepoTable;
import com.ruoyi.report.model.dto.repo.DataSourceDTO;
import com.ruoyi.report.model.vo.BillResultVO;
import com.ruoyi.report.model.vo.ResultVO;
import com.ruoyi.report.service.RepoService;
import com.ruoyi.report.utils.ResultVOUtils;
import oracle.jdbc.proxy.annotation.Post;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 数据报表接口,数据大屏接口
 */
@RestController
@RequestMapping("/colorful-fog/RepoController")
public class RepoController {
    @Resource
    RepoService repoService;

    @Resource
    RedissonClient redissonClient;

    /**
     * 获取数据
     */
    @PostMapping("/getData")
    public ResultVO<Map<String, Map<String, Double>>> getData(@RequestBody DataSourceDTO dataSourceDTO) {
        return ResultVOUtils.success(repoService.getData(dataSourceDTO));
    }

    /**
     * 存放json数据
     */
    @PostMapping("/saveRepoJson")
    public ResultVO<String> saveData(@RequestBody Object repoJson) {
        //存放到redis中
        redissonClient.getBucket("json").set(repoJson);
        return ResultVOUtils.success();
    }

    /**
     * 查询图表信息
     */
    @PostMapping("/getRepoTable")
    public ResultVO getRepoConfig(@RequestBody RepoTable repoTable, @RequestParam Integer currentPage, @RequestParam Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        PageInfo<RepoTable> pageInfo = new PageInfo<>(repoService.list(repoTable));
        return ResultVOUtils.success(pageInfo);
    }

    /**
     * 根据id查询图表信息
     */
    @PostMapping("/getById")
    public ResultVO<RepoTable> getById(@RequestParam String repoId) {
        return ResultVOUtils.success(repoService.getById(repoId));
    }

    /**
     * 保存或者修改图表信息
     */
    @PostMapping("/saveOrUpdateRepo")
    public ResultVO<String> saveOrUpdateRepo(@RequestBody RepoTable repoTable) {
        repoService.saveOrUpdateRepo(repoTable);
        return ResultVOUtils.success();
    }

    /**
     * 删除图表信息
     */
    @PostMapping("/deleteRepo")
    public ResultVO<String> deleteRepo(@RequestParam String repoId) {
        repoService.deleteRepo(repoId);
        return ResultVOUtils.success();
    }



}
